/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package swingDemoEvent;

/**
 *
 * @author Administrator
 */
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


/**
 * 按照工资排序。
 * 
 * @author
 */
public class SortTest {
  public static void main(String args[]) {
    List<User> list = new ArrayList<User>();
    list.add(new User("张三", 1000));
    list.add(new User("李四", 1500));
    list.add(new User("王五", 1000));
    list.add(new User("赵六", 1200));
    list.add(new User("笑笑", 1500));
    list.add(new User("细细", 1800));
    Collections.sort(list);
    for (User o : list) {
      System.out.println(o.name + "=" + o.salary);
    }
  }
}
class User implements Comparable<User> {
  User(String name, int salary) {
    this.name = name;
    this.salary = salary;
  }

  public int compareTo(User obj) {
      return obj.salary - this.salary;
  }
  String name;
  int salary;
}
